<script setup>
import { ref, onMounted } from 'vue';
import GameSimpleItem from "@/components/FrontComponents/GameSimpleItem.vue";
import {gameRecommendGetAPI} from "@/api/FrontApi/game.js";
import {useRouter} from "vue-router";

defineProps({
  gameDetail: Object,
  category: Array
})

const router = useRouter()

// 获取推荐信息
const gameRecommendList = ref([])
const getRecommendGame = async () => {
  const res = await gameRecommendGetAPI({length: 4, sort: 0})
  gameRecommendList.value = res.data
}
onMounted(async () => {
  await getRecommendGame()
/*  await nextTick()
  descriptionContentHeight.value = descriptionContent.value.scrollHeight
  descriptionContainerHeight.value = descriptionContainer.value.clientHeight
  console.log(descriptionContentHeight.value, descriptionContainerHeight.value)*/
})

const isExpanded = ref(false);

const toggleExpand = () => {
  isExpanded.value = !isExpanded.value;
};

/*const descriptionContainer = ref(null);
const descriptionContent = ref(null);
const descriptionContentHeight = ref()
const descriptionContainerHeight = ref()
const checkShowMoreButton = () => {
  isExpanded.value = descriptionContentHeight.value < descriptionContainerHeight.value
}

watchEffect(() => {
  checkShowMoreButton();
});*/
</script>

<template>
  <div class="game-detail">
    <div class="container">
      <div class="left">
        <div :class="['description', { expanded: isExpanded }]">
          <div v-html="gameDetail.description"></div>
        </div>
        <div class="footer">
          <div class="show-more" v-if="isExpanded === false" @click="toggleExpand">展开阅读</div>
        </div>
      </div>
      <div class="right">
        <div class="category">
          <div class="desc">该游戏的所属分类：</div>
          <div class="category-list">
            <span @click="router.push(`/store/category/${item.id}`)" v-for="item in category" :key="item.id">{{item.name}}</span>
          </div>
        </div>
        <div class="recommend">
          <div class="desc">为您推荐：</div>
          <div class="game-list">
            <div class="item" v-for="item in gameRecommendList" :key="item">
              <GameSimpleItem :game="item"></GameSimpleItem>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.game-detail {
  .container {
    width: 1040px;
    display: flex;
    justify-content: space-between;
    .left {
      display: flex;
      flex-direction: column;
      justify-content: start;
      .description {
        padding: 8px;
        width: 616px;
        color: #cccccc;
        height: 1040px;
        overflow: hidden;
        position: relative;
        background: linear-gradient(to top, #001528 0px, $backgroundColor2 300px);
        border-bottom: 3px solid #001528;;
      }
      .expanded {
        height: auto;
        overflow: visible;
        background: none;
        border-bottom: none;
      }
      .footer {
        display: flex;
        justify-content: end;
        .show-more {
          margin-top: 6px;
          padding: 6px;
          color: #ccc;
          border: none;
          cursor: pointer;
          border-radius: 4px;
          &:hover {
            color: #fff;
          }
        }
      }
    }
    .right {
      margin-top: 30px;
      width: 300px;
      .category {
        .desc {
          margin-bottom: 12px;
          color: #cccccc;
          font-size: 18px;
        }
        .category-list {
          display: flex;
          flex-wrap: wrap;
          span {
            margin: 0 6px 4px 0;
            padding: 2px 4px;
            display: inline-block;
            font-size: 18px;
            color: #67c1f5;
            border-radius: 4px;
            background-color: rgba(103, 193, 245, 0.2);
            cursor: pointer;
            &:hover {
              color: #fff;
            }
          }
        }
      }
      .recommend {
        margin-top: 30px;
        display: flex;
        flex-direction: column;
        .desc {
          margin-bottom: 12px;
          color: #cccccc;
          font-size: 18px;
        }
        .game-list {
          .item {
            margin-bottom: 20px;
          }
        }
      }
    }
  }
}
</style>
